using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

namespace AudioStudio
{
    /// <summary>
    /// 用于设置rtpc
    /// </summary>
    [AddComponentMenu("AudioStudio/SliderSound")]
    public class SliderSound : MonoBehaviour
    {
        public RTPC ValueChangeRTPC;
        public AudioEvent[] audioEvents;

        void Start()
        {
            Slider s = this.gameObject.GetComponent<Slider>();
            if (s != null)
            {
                s.onValueChanged.AddListener(x =>
                {
                    ValueChangeRTPC.SetValue(s.value);
                    PlaySound();
                    //Debug.LogError("PlaySound: "+ s.value);
                });
            }
        }
        void PlaySound()
        {
            if (AkSoundEngine.IsInitialized())
            {
                AudioManager.Instance.PostEvents(null, audioEvents);
            }
        }
    }   
}

